package efrei.ngo.entity;

import efrei.ngo.util.DatabaseAccess;

public class User {
	private int u_id;
	private String email;
	private String username;
	private boolean isValid;
	private int random;
	private char auth;

	public User(int id){
		this.u_id=id;
		DatabaseAccess.connectToDB();
		this.username=DatabaseAccess.dbGetNameViaID(id);
		DatabaseAccess.endConnectionToDB();
	}
	
	public User(int id, String name){
		this.u_id=id;
		this.username=name;
	}
	
	public User(String email, String username) {
		super();
		this.email = email;
		this.username = username;
	}
	
	public User(String username){
		this.username=username;
		DatabaseAccess.connectToDB();
		this.u_id=DatabaseAccess.dbGetIDViaName(username);
		DatabaseAccess.endConnectionToDB();
	}
	
	public int getU_id() {
		return u_id;
	}

	public void setU_id(int u_id) {
		this.u_id = u_id;
	}

	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public boolean isValid() {
		return isValid;
	}
	public boolean validate(String psw){
		if(this.username.equals("")){
			this.isValid=DatabaseAccess.dbLoginViaEmail(this.email, psw, this);
		}else{
			this.isValid=DatabaseAccess.dbLoginViaUsername(this.username, psw, this);
		}
		return this.isValid;
	}
	public char getAuth() {
		return auth;
	}
	public void setAuth(char auth) {
		this.auth = auth;
	}
	
}
